clear
set matsize 800
cd "C:\Users\jedwab\Desktop\Replication Files JJK 2023 JUE\Stata"
set more off, permanently

***********************************
***********************************
* FIGURES AND REGRESSION ANALYSIS *
***********************************
***********************************

****************
*** FIGURE 1 *** 
****************

* Created in the folder "Figure1"

****************
*** FIGURE 2 ***
****************

** FIGURE 2A **
use finaljjk4, clear
* We modify the month variable to express it relative to the starting date in Europe.
gen months_oct13474 = start_month-10 if start_year == 1347
replace months_oct13474 = 2 + start_month if start_year == 1348
replace months_oct13474 = 14 + start_month if start_year == 1349
replace months_oct13474 = 26 + start_month if start_year == 1350
count if months_oct13474!= . & year == 1300
keep if mortality != .& months_oct1347 !=.
twoway (scatter mortality months_oct1347, mcolor(gs8))(qfit mortality months_oct1347, lcolor(black) lpattern(dash) lwidth(thick)), ytitle(Black Death Mortality Rate 1347-1352 (%)) ytitle(, margin(small)) xlabel(0(12)36) ylabel(10(10)80) xtitle(Number of Months Between First Infection and October 1347) xtitle(, margin(small)) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) legend(off)
graph use "figure2amort.gph"
graph export "FinalFigures\figure2A.png", replace width(2620) height(1908)

** FIGURE 2B **
use finaljjk4, clear
* We reorder the month variable. 
gen start_month1 = start_month
gen start_year1 = start_year
foreach X in 1 {
reg mortality start_year`X' if year == 1300
predict mortality`X' if year == 1300, resid
bysort start_month`X': egen start_month`X'_mean = mean(mortality`X') if year == 1300
}
gen start_month1_35 = start_month1+3.5
replace start_month1_35 = start_month1_35 - 12 if start_month1_35 >= 13
twoway (scatter start_month1_mean start_month1_35, mcolor(gs8))(qfit start_month1_mean start_month1_35 if start_month1_35 >= 2.5, lcolor(black) lpattern(dash) lwidth(thick)), xlabel(1(1)12) ytitle(Mortality Rate (%) Purged from Year of Infection FE) ytitle(, margin(small)) ylabel(-15(5)10) xtitle(Month of Peak Infection (First Infection + 3.5 Months)) xtitle(, margin(small)) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) legend(off)
graph use "figure2bmort.gph"
graph export "FinalFigures\figure2B.png", replace width(2620) height(1908)

****************
*** FIGURE 3 ***
****************

use finaljjk4, clear
keep if samplemort == 1
keep if year == 1300
count
* 165
* FIGURE 3A *
twoway (scatter mortality lpop1300, mcolor(black) msize(medsmall) msymbol(circle) mlabel(city_jjk) mlabsize(vsmall) mlabcolor(black)) (lfit mortality lpop1300, lcolor(black) lwidth(medthick) lpattern(dash)), ytitle(Black Death Mortality Rate (%) in 1347-1352) xtitle(Log Population (1000s Inhabitants) in 1300) ytitle(, margin(medsmall)) xlabel(0(1)6) xtitle(, margin(medsmall)) legend(off) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph export "FinalFigures\figure3A.png", replace width(2620) height(1908)
reg mortality lpop1300, robust
* FIGURE 3B *
twoway (scatter mortality lma1300_speed2_38, mcolor(black) msize(medsmall) msymbol(circle) mlabel(city_jjk) mlabsize(vsmall) mlabcolor(black)) (lfit mortality lma1300_speed2_38, lcolor(black) lwidth(medthick) lpattern(dash)), ytitle(Black Death Mortality Rate (%) in 1347-1352) xtitle(Log Market Access in 1300) ytitle(, margin(medsmall)) xlabel(-6(1)6) xtitle(, margin(medsmall)) legend(off) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph export "FinalFigures\figure3B.png", replace width(2620) height(1908)
reg mortality lma1300_speed2_38, robust

****************
*** FIGURE 4 ***
****************

use finaljjk4, clear 
keep if samplemort == 1 & mortality != .
count if year == 1300
drop changepop
* We create the panel variable
sort countrycity year
bysort countrycity: gen changepop=(pop-pop[_n-1])/pop[_n-1]*100
bysort countrycity: gen lag1pop=pop[_n-1]
* We create the mortality*year interactions
gen mortality1200 = 0
replace mortality1200 = mortality if year == 1200
gen mortality1300 = 0
replace mortality1300 = mortality if year == 1300
gen mortality1400 = 0
replace mortality1400 = mortality if year == 1400
gen mortality1500 = 0
replace mortality1500 = mortality if year == 1500
gen mortality1600 = 0
replace mortality1600 = mortality if year == 1600
gen mortality1700 = 0
replace mortality1700 = mortality if year == 1700
gen mortality1750 = 0
replace mortality1750 = mortality if year == 1750

* Regressions and coefficients for Figure 4
** NON-PANEL **
drop sample
xi: reg changepop mortality1200-mortality1750 i.year [pw = lag1pop] if year >= 1200 & year <= 1750, robust cluster(countrycity)
gen sample = e(sample)
outreg2 mortality* using table_panel_figure.xls, addtext(wgt, 1100) sideway se tex(landscape) nocons coefastr dec(5) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
* PANEL *
drop sample
xi: areg changepop mortality1200-mortality1700 i.year [pw = lag1pop] if year >= 1200 & year <= 1750, robust absorb(countrycity) cluster(countrycity)
gen sample = e(sample)
outreg2 mortality* using table_panel_figure.xls, addtext(wgt, 1100) sideway se tex(landscape) nocons coefastr dec(5) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* We export the results to an excel file
* We then reimport a modified excel file with the coefficients to create the figure
clear
import excel "coef_panel_figure4.xlsx", sheet("Sheet1") firstrow clear
foreach X in coef {
replace `X' = `X'*100 if spec == "log"
}
keep if var == "continuous"
* We use the nofe and pctchange specifications
twoway (connected coef year if spec == "nofe", mcolor(gs8) msize(medsmall) lpattern(dash) msymbol(circle) mlabel(star) mlabcolor(gs8))(connected coef year if spec == "pctchange", mcolor(black) msize(medsmall) msymbol(circle) mlabel(star) mlabcolor(black)), ytitle(Cumulative Effect of Black Death Mortality (%) in Each Year) xtitle(.) ytitle(, margin(medsmall)) xtitle(, margin(medsmall)) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) xlabel(1200(100)1700) legend(order(1 "Non-Panel" 2 "Panel"))
graph use "fig4panel.gph"
graph export "FinalFigures\figure4.png", replace width(2620) height(1908)

****************
*** FIGURE 5 ***
****************

* We obtain the rank of each city in 1400 and 1600
use finaljjk4, clear
keep if samplemort == 1 & year >= 1300 & year <= 1850
count
* 165
keep if year == 1300
gsort- pop1300
gen rank1300 = _n
gsort- pop1400
gen rank1400 = _n
gsort- pop1600
gen rank1600 = _n
keep city_id city_jjk rank* pop1300 pop1600 mortality lpop* countryname
gen minrank1600 = -rank1600
gen minrank1300 = -rank1300
twoway (scatter minrank1600 minrank1300, mlabel(city_jjk) msize(vsmall))(lfit minrank1300 minrank1300), ytitle((-) Rank 1600) xtitle((-) Rank 1300) ylabel(-160(50)0) xlabel(-160(50)0) legend(off)
* We modify manually and export
graph use "rank_45deg_line.gph"
graph export "FinalFigures\figure5.png", replace width(2620) height(1908)

****************
*** FIGURE 6 ***
****************

* We obtain the population share for the selected factors altogether. 
foreach X in tradeall {
use finaljjk4, clear 
gen rd_int = (DMajRomIntersection_10 == 1 | DAnyRmRdIntersection_10 == 1 | dist2landrouteint_10 == 1)
gen tradeall = (rd_int == 1 | HansaFixed == 1 | dist2AMNB_10 == 1 | rivers_10 == 1)
tab tradeall samplemort if year == 1400
count if year == 1300
* 165
gen share_165 = `X' if samplemort == 1
gen share_all = `X' 
collapse (mean) share_165 share_all [w=pop], by(year)
}
keep if year >= 1100 & year <= 1750
* We create the extrapolation. 
gen share_165_2 = share_165 if year <= 1300
ipolate share_165_2 year, generate(share_165_extrap) epolate
drop share_165_2
gen share_all_2 = share_all if year <= 1300
ipolate share_all_2 year, generate(share_all_extrap) epolate
drop share_all_2
twoway (line share_all_extrap year if year >= 1300, lpattern(dash) lcolor(black) lwidth(thick))(line share_all year, lcolor(black) lwidth(thick)) if year >= 1100 & year <= 1750, xline(1350, lpattern(longdash) lcolor(gs6) lwidth(medium)) xlabel(1100(100)1700) legend(off) ytitle(Share Urban Pop. w/i 10 km from Trade Fixed Factors)
* We manually modify and export the figure
graph use "urban_reset_1801.gph"
graph export "FinalFigures\figure6.png", replace width(2620) height(1908)

****************
*** FIGURE 7 ***
****************

*** FIGURE 7a ***
* These are the betas that we obtained from Table 8
* We group them into different groups and obtain and show their sum
clear
import excel "sumbetas.xlsx", sheet("raw") firstrow
keep if var == "sumfix" | var == "sumlpop" | var == "suminst"
reshape long absvalbeta, i(var) j(year)
* We manually modify and export the figure
graph use "sumbetas_new.gph"
graph export "FinalFigures\figure7a.png", replace width(2620) height(1908)

*** FIGURE 7b ***
*** SHARE RIVERS OVER TIME **
* We run the regressions and obtain the contribution (BX) of each factor
use data_for_het, clear
gen cer = invcerealclosest
gen pot = potatolowclosest
gen pas = pastoral_weak_closest
gen coa = coast
gen riv = river
gen rdi = rd_int
gen han = HansaFixed
gen lpo = lpop1353
gen mon =  monarchy
gen cap = Bcapital 
gen rep = representative1300
keep city_jjk changepop* cer-rep pop1300 year pop2015min mortality pop1400 pop1500 pop1600 pop1700 pop1750
local agri "cer pot pas"
local trade "coa riv rdi han"
local ctrls "lpo mon cap rep" 
local all "`agri' `trade' `ctrls'"
ren changepop13002015min changepop13002015
ren pop2015min pop2015
capture erase table_het.xls
capture erase table_het.tex
capture erase table_het.txt
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
* 1400 *
tobit changepop1400 mortality m_* ``Y'' [pw = pop1300] if year == 1400, vce(robust) ll(-100)
gen b_cons1400 = _b[_cons]
predict pchgpop1400, ystar(-100,.)
margins, dydx(*) predict (ystar(0,.)) post atmeans
foreach X of local `Y' {
gen b_`X'1400 = _b[`X']
gen b_m_`X'1400 = _b[m_`X']
}
gen b_mort1400 = _b[mortality]
outreg2 * using table_het.xls, se tex(landscape) addtext(year, 1400) keep(mortality *coast* *river*) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
* 1500-1850 *
foreach N in 1500 1600 1700 1750 1800 1850 {
tobit changepop1300`N' mortality m_* ``Y'' [pw = pop1300] if year == `N', vce(robust) ll(-100)
gen b_cons`N' = _b[_cons]
predict pchgpop`N', ystar(-100,.) 
margins, dydx(*) predict (ystar(0,.)) post atmeans
foreach X of local `Y' {
gen b_`X'`N' = _b[`X']
gen b_m_`X'`N' = _b[m_`X']
}
gen b_mort`N' = _b[mortality]
outreg2 * using table_het.xls, se tex(landscape) addtext(year, 1500) keep(mortality *coast* *river) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
}
* 2015 *
foreach N in 2015 {
tobit changepop1300`N' mortality m_* ``Y'' [pw = pop1300] if year == 1850, vce(robust) ll(-100)
gen b_cons`N' = _b[_cons]
predict pchgpop`N', ystar(-100,.) 
margins, dydx(*) predict (ystar(0,.)) post atmeans
foreach X of local `Y' {
gen b_`X'`N' = _b[`X']
gen b_m_`X'`N' = _b[m_`X']
}
gen b_mort`N' = _b[mortality]
outreg2 * using table_het.xls, se tex(landscape) addtext(year, 1500) keep(mortality *coast* *river) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
}
* For each factor one by one
foreach N in 1400 1500 1600 1700 1750 1800 1850 2015 {
foreach X of local `Y' {
gen pchgpop`N'_mort = b_mort`N'*mortality
gen pchgpop`N'_m_`X' = b_m_`X'`N'*`X'*mortality
gen pchgpop`N'_reco_`X' = pchgpop`N'_mort+pchgpop`N'_m_`X'
drop pchgpop`N'_mort
}
}
* Based on mortality
foreach N in 1400 1500 1600 1700 1750 1800 1850 2015 {
gen pchgpop`N'_mort = b_mort`N'*mortality
}
}
save contrib_ystar_atm, replace
* We then focus on rivers. 

* UNCONDITIONAL
* Prediction of pop based on the model
use contrib_ystar_atm, clear
keep if year == 1750
keep if riv == 1
keep pop* city_jjk 
reshape long pop, i(city_jjk) j(year)
collapse (sum) pop, by(year)
ren pop pop1
sort year
save riverpop, replace

* Share with a river - unconditional
use contrib_ystar_atm, clear
keep if year == 1750
keep if riv == 0
keep pop* city_jjk
reshape long pop, i(city_jjk) j(year)
collapse (sum) pop, by(year)
ren pop pop0
sort year
merge year using riverpop
tab _m
drop _m
gen river_sh_uncond = pop1/(pop0+pop1)*100
keep year river_sh_uncond
sort year
save riverpop_uncond, replace

* CONDITIONAL
* Prediction of pop based on the model
use contrib_ystar_atm, clear
keep city_jjk year b_m_riv* riv mortality pop1300
keep if year == 1750
foreach N in 1400 1500 1600 1700 1750 2015 {
gen pctchgpop_riv_`N' = riv*mortality*b_m_riv`N'
}
keep city_jjk year pop1300 pctchgpop_riv_* riv
foreach N in 1400 1500 1600 1700 1750 2015 {
gen pop`N'= pop1300/100*(100+pctchgpop_riv_`N')
}
keep if riv == 1
keep pop* city_jjk 
reshape long pop, i(city_jjk) j(year)
collapse (sum) pop, by(year)
ren pop pop1
sort year
save riverpop, replace

* Share with a river - conditional
use contrib_ystar_atm, clear
keep if riv == 0
keep if year == 1750
keep city_jjk pop*
reshape long pop, i(city_jjk) j(year)
collapse (sum) pop, by(year)
ren pop pop0
sort year
sort year
merge year using riverpop
tab _m
drop _m
gen river_sh_cond = pop1/(pop0+pop1)*100
keep year river_sh_cond
sort year
save riverpop_cond, replace

* We combine and create the figure. 
use riverpop_uncond, clear
sort year
merge year using riverpop_cond
tab _m
drop _m
twoway (connected river_sh_uncond year) (connected river_sh_cond year), ytitle(Population Share Along a River (%))legend(order(1 "Unconditional Share" 2 "Conditional Share") rows(1)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph use "popshriver165.gph"
graph export "FinalFigures\figure7b.png", replace width(2620) height(1908)

***************
*** TABLE 1 ***
***************

use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165
drop sample

** (1) 1300-1400 **
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace 
test mortality = -1
gen sample = e(sample)
foreach X in changepop1400 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
drop sample
sum mean
reg z mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
drop z mean std

** (2) 1300-1500 **
sum changepop13001500 [w = pop1300] if year == 1500
reg changepop13001500 mortality [pw = pop1300] if year == 1500, robust 
reg changepop13001500 mortality [pw = pop1300] if year == 1500, robust beta
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
test mortality = -1
gen sample = e(sample)
foreach X in changepop13001500 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
drop sample
sum mean
reg z mortality [pw = pop1300] if year == 1500, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
drop z mean std

** (3) 1300-1600 **
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust beta
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
gen sample = e(sample)
foreach X in changepop13001600 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
sum mean
drop sample
reg z mortality [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
drop z mean std

** (4) 1300-1700 **
reg changepop13001700 mortality [pw = pop1300] if year == 1700, robust beta
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
sum mortality changepop13001750 if year == 1750
gen sample = e(sample)
foreach X in changepop13001700 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
sum mean
drop sample
reg z mortality [pw = pop1300] if year == 1700, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
drop z mean std

** (5) 1300-1750 **
reg changepop13001750 mortality [pw = pop1300] if year == 1750, robust beta
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
gen sample = e(sample)
foreach X in changepop13001750 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
sum mean
drop sample
reg z mortality [pw = pop1300] if year == 1750, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%)
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
drop z mean std

** (6) 1300-1850 ** 
reg changepop13001850 mortality [pw = pop1300] if year == 1850, robust
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
gen sample = e(sample)
foreach X in changepop13001850 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
sum mean
drop sample
reg z mortality [pw = pop1300] if year == 1850, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
drop z mean std

** (7) 1300-2015 ** 
reg changepop13002015min mortality [pw = pop1300] if year == 1850, robust
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
gen sample = e(sample)
foreach X in changepop13002015min {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
sum mean
drop sample
reg z mortality [pw = pop1300] if year == 1850, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%)
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
drop z mean std

** (8) 1200-1300 ** 
reg changepop1300 mortality [pw = pop1200] if year == 1300, robust
outreg2 mortality using "FinalTables\table1_se.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
outreg2 mortality using "FinalTables\table1_ci.xls", ci tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
gen sample = e(sample)
foreach X in changepop1300 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen z = (`X'-mean)/std if sample == 1
sum z, d
}
sum mean 
drop sample
reg z mortality [pw = pop1200] if year == 1300, robust
outreg2 mortality using "FinalTables\table1_Z_se.xls", se tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
outreg2 mortality using "FinalTables\table1_Z_ci.xls", ci tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
drop z mean std

***************
*** TABLE 2 ***
***************

use finaljjk4, clear 
keep if samplemort == 1
count if year == 1300
* 165
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 lma1300_speed2_38 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"

* (1) PHYSICAL GEOGRAPHY ONLY
reg mortality `geo' if year == 1400 & sample == 1, robust
outreg2 * using "FinalTables\table2.xls", se tex(landscape) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace

* (2) ECONOMIC GEOGRAPHY ONLY
reg mortality `ecogeo' if year == 1400 & sample == 1, robust
outreg2 * using "FinalTables\table2.xls", se tex(landscape) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* (3) INSTITUTIONS ONLY
reg mortality `pol' if year == 1400 & sample == 1, robust
outreg2 * using "FinalTables\table2.xls", se tex(landscape) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* (4) ALL
reg mortality `geo' `ecogeo' `pol' if year == 1400 & sample == 1, robust
outreg2 * using "FinalTables\table2.xls", se tex(landscape) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

***************
*** TABLE 3 ***
***************

use finaljjk4, clear 
keep if samplemort == 1
count if year == 1300
* 165
drop sample

*** Main coefficients ***

* 1. Baseline
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* 2. Controls
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 lma1300_speed2_38 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
reg changepop1400 mortality `geo' `ecogeo' `pol' [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, all ctrls) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality `geo' `ecogeo' `pol' [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, all ctrls) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* 3. Country FE
codebook countryname
areg changepop1400 mortality [pw = pop1300] if year == 1400, robust absorb(countryname)
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, country FE) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
areg changepop13001600 mortality [pw = pop1300] if year == 1600, robust absorb(countryname)
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, country FE) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* 4. 7 states
codebook entity1300_old if year == 1400
* We obtain the number of cities per state.
gen count = 1 if year == 1300 & sample == 1 & mortality != .
bysort entity1300_old: egen entity300_old = sum(count) if year == 1300 & sample == 1 & mortality != .
bysort entity1300_old: egen entity1300_old_num = max(entity300_old) 
areg changepop1400 mortality [pw = pop1300] if year == 1400 & entity1300_old_num >=5, robust absorb(entity1300_old)
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, state FE_atleast5) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
areg changepop13001600 mortality [pw = pop1300] if year == 1600 & entity1300_old_num >=5, robust absorb(entity1300_old)
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, state FE_atleast5) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* 5. Cell FE
gen longitude_mega = round(longitude,5)
gen latitude_mega = round(longitude,5)
gen cell = string(longitude_mega) + " " + string(latitude_mega)
codebook cell
areg changepop1400 mortality [pw = pop1300] if year == 1400, robust absorb(cell)
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, cell FE) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
areg changepop13001600 mortality [pw = pop1300] if year == 1600, robust absorb(cell)
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) se tex(landscape) addtext(test, cell FE) side nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 6 **
use finaljjk4, clear
drop sample
keep if samplemort == 1
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly3 "longitude2 latitude2 longitude3 latitude3"
* 1400
xi: ivreg2 changepop1400 `geo' `ecogeo' `pol' `poly3' (mortality = messina_euclidean) euromena1_wl_euclidean [pw = pop1300] if year == 1400 & city_jjk != "NEW-ROSS" & city_jjk != "MESSINA", robust cluster(entity1300) gmm2s first
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* 1600
xi: ivreg2 changepop13001600 `geo' `ecogeo' `pol' `poly3' (mortality = messina_euclidean) euromena1_wl_euclidean  [pw = pop1300] if year == 1600 & city_jjk != "NEW-ROSS" & city_jjk != "MESSINA", robust cluster(entity1300) gmm2s first
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* IV F-stat = 22.3

** Row 7 **
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 lma1300_speed2_38 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly3 "longitude2 latitude2 longitude3 latitude3"
* 1400
xi: ivreg2 changepop1400 `geo' `ecogeo' `pol' `poly3' (mortality = i.start_month_35) i.start_year [pw = pop1300] if year == 1400, robust gmm2s cluster(entity1300) first 
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* 1600
xi: ivreg2 changepop13001600 `geo' `ecogeo' `pol' `poly3' (mortality = i.start_month_35) i.start_year [pw = pop1300] if year == 1600, robust gmm2s cluster(entity1300) first
outreg2 mortality using "FinalTables\table3.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 

***************
*** TABLE 4 ***
***************

*** COL (1) ***

use finaljjk4, clear
drop sample
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\table4.xls", se addtext(unit, baseline, pop, intensive) tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace 
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\table4.xls", se addtext(unit, baseline, pop, intensive) tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 

*** COL (2) ***

* We obtain the sum of population by entity. 
use finaljjk4, clear
foreach X in 1300 1400 1500 1600 1700 1750 1800 1850 { 
gen pop`X'_tot = pop`X' 
gen pop`X'_int = pop`X' if pop1300 != .
gen pop`X'_ext = pop`X' if pop1300 == .
gen pop`X'_num = (pop`X'_ext !=. & pop`X'_ext >= 1)
}
collapse (sum) pop*_tot pop*_int pop*_ext pop*_num, by(entity1300_old)
sort entity1300
save regional_pop, replace

* Mean mortality by entity. 
use finaljjk4, clear
keep if year == 1300
collapse (mean) mortality mortality274 [iw = pop1300_05], by(entity1300_old)
sort entity1300
merge entity1300 using regional_pop
tab _m
drop _m
sort entity
* We obtain the changes in population. 
gen changepop1400_int=(pop1400_int-pop1300_int)/pop1300_int*100
foreach X in 1500 1600 1700 1750 1800 1850 { 
gen changepop1300`X'_int=(pop`X'_int-pop1300_int)/pop1300_int*100
}
gen changepop1400_tot=(pop1400_tot-pop1300_tot)/pop1300_tot*100
foreach X in 1500 1600 1700 1750 1800 1850 { 
gen changepop1300`X'_tot=(pop`X'_tot-pop1300_tot)/pop1300_int*100
}
gen changepop1400_num=(pop1400_num-pop1300_num)/pop1300_int*100
foreach X in 1500 1600 1700 1750 1800 1850 { 
gen changepop1300`X'_num=(pop`X'_num-pop1300_num)/pop1300_int*100
}

reg changepop1400_int mortality274, robust
outreg2 mortality274 using "FinalTables\table4.xls", se addtext(unit, state, pop, intensive) tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 

reg changepop13001600_int mortality274, robust
outreg2 mortality274 using "FinalTables\table4.xls", se addtext(unit, state, pop, intensive) tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 

*** COL (3) ***

reg changepop1400_tot mortality274, robust
outreg2 mortality274 using "FinalTables\table4.xls", se addtext(unit, state, pop, total) tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 

reg changepop13001600_tot mortality274, robust
outreg2 mortality274 using "FinalTables\table4.xls", se addtext(unit, state, pop, total) tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 

*** COL (4)-(5) ***

use finaljjk4, clear
keep if samplemort == 1
count
* 165
gen state = mort_entity1300_old
gen distance10pctil = mortdist332

foreach X in state distance10pctil {
gen nonlocal = `X'
reg changepop1400 mortality nonlocal [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\table4.xls", se addtext(test, "`X'") tex(landscape) nocons coefastr dec(2) sdec(2) bdec(2) noni nolabel bracket title(Effect, "") nonotes append 
drop nonlocal
}
foreach X in state distance10pctil {
gen nonlocal = `X'
reg changepop13001600 mortality nonlocal [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\table4.xls", se addtext(test, "`X'") tex(landscape) nocons coefastr dec(2) sdec(2) bdec(2) noni nolabel bracket title(Effect, "") nonotes 
drop nonlocal
}

*** COL (6)-(7) ***

use finaljjk4, clear
* We drop existing cities in 1300
drop if pop1300 >=1 & pop1300 != .
* 1335
foreach X in 1400 1500 1600 1700 1750 1800 1850 {
gen city_yn_`X' = (pop`X' != . & pop`X' >= 1)
}
drop mortality 
ren mortality274 mortality
drop sample 

foreach X in 1400 {
reg city_yn_`X' mortality if year == `X', robust beta
outreg2 mortality using "FinalTables\table4.xls", se addtext(unit, city, pop, dummy if exists) tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
}
foreach X in 1600 {
reg city_yn_`X' mortality if year == `X', robust beta
outreg2 mortality using "FinalTables\table4.xls", se addtext(unit, city, pop, dummy if exists) tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
} 


** COL (7) **

foreach X in 1400 {
reg lpop`X'_05 mortality if year == `X', robust beta
outreg2 mortality using "FinalTables\table4.xls", se addtext(unit, city, pop, log pop) tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
} 
foreach X in 1600 {
reg lpop`X'_05 mortality if year == `X', robust beta
outreg2 mortality using "FinalTables\table4.xls", se addtext(unit, city, pop, log pop) tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
} 

***************
*** TABLE 5 ***
***************

use finaljjk4, clear
keep if samplemort == 1
count
* 165
gen state = mort_entity1300_old
gen distance10pctil = mortdist332
drop sample

** 1400 ** 
capture erase table5.xls
capture erase table5.tex
capture erase table5.txt
foreach X in state {
gen nonlocal = `X'
gen interact = mortality*`X'
reg changepop1400 mortality nonlocal interact [pw = pop1300] if year == 1400, robust
outreg2 * using "FinalTables\table5.xls", se addtext(test, "`X'") tex(landscape) nocons coefastr dec(2) sdec(2) bdec(2) noni nolabel bracket title(Effect, "") nonotes replace
drop nonlocal interact*
}
foreach X in distance10pctil {
gen nonlocal = `X'
gen interact = mortality*`X'
reg changepop1400 mortality nonlocal interact [pw = pop1300] if year == 1400, robust
outreg2 * using "FinalTables\table5.xls", se addtext(test, "`X'") tex(landscape) nocons coefastr dec(2) sdec(2) bdec(2) noni nolabel bracket title(Effect, "") nonotes append
drop nonlocal interact*
}
gen sample = e(sample)
foreach X in changepop1400 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen Z = (`X'-mean)/std if sample == 1
}
drop mean std sample
foreach X in state distance10pctil {
gen nonlocal = `X'
gen interact = mortality*`X'
reg Z mortality nonlocal interact [pw = pop1300] if year == 1400, robust
outreg2 * using "FinalTables\table5.xls", se addtext(test, "`X'") tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop nonlocal interact*
}
drop Z

** 1600 **
foreach X in state distance10pctil {
gen nonlocal = `X'
gen interact = mortality*`X'
reg changepop13001600 mortality nonlocal interact [pw = pop1300] if year == 1600, robust
outreg2 * using "FinalTables\table5.xls", se addtext(test, "`X'") tex(landscape) nocons coefastr dec(2) sdec(2) bdec(2) noni nolabel bracket title(Effect, "") nonotes 
drop nonlocal interact*
}
gen sample = e(sample)
foreach X in changepop13001600 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen Z = (`X'-mean)/std if sample == 1
}
drop mean std sample
foreach X in state distance10pctil {
gen nonlocal = `X'
gen interact = mortality*`X'
reg Z mortality nonlocal interact [pw = pop1300] if year == 1600, robust
outreg2 * using "FinalTables\table5.xls", se addtext(test, "`X'") tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop nonlocal interact*
}
drop Z

***************
*** TABLE 6 ***
***************

use dmvdata, clear

* COLUMNS (1)-(3)
sum chgpop12901377new chgpop12901756new chgpop10861290new if Plague_mortality_clergy != . & county != "Cornwall"
reg chgpop12901377new Plague_mortality_clergy [iw = pop1290new] if county != "Cornwall", robust beta
outreg2 Plague_mortality_clergy using "FinalTables\table6_cols_1_3.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
reg chgpop12901756new Plague_mortality_clergy [iw = pop1290new] if county != "Cornwall", robust beta
outreg2 Plague_mortality_clergy using "FinalTables\table6_cols_1_3.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
reg chgpop10861290new Plague_mortality_clergy [iw = pop1086new] if county != "Cornwall", robust beta
outreg2 Plague_mortality_clergy using "FinalTables\table6_cols_1_3.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
* Same but with a Z-score of the dependent variable
reg chgpop12901377new_std Plague_mortality_clergy [iw = pop1290new] if county != "Cornwall", robust beta
outreg2 Plague_mortality_clergy using "FinalTables\table6_cols_1_3.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
reg chgpop12901756new_std Plague_mortality_clergy [iw = pop1290new] if county != "Cornwall", robust beta
outreg2 Plague_mortality_clergy using "FinalTables\table6_cols_1_3.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
reg chgpop10861290new_std Plague_mortality_clergy [iw = pop1086new] if county != "Cornwall", robust beta
outreg2 Plague_mortality_clergy using "FinalTables\table6_cols_1_3.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 

* COLUMNS (4)-(6)
foreach X in DMVsper100Kacre {
reg `X' Plague_mortal lpop1290new lCountyAcreage [pw = pop1290new], robust beta
outreg2 * using "FinalTables\table6_cols_4_6.xls", addtext(test,all,wt,pop1290,ctrls,yes) keep(Plague*) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
}
foreach Z in 10 {
foreach X in in`Z'd out`Z'd {
reg `X' Plague_mortal lpop1290new lCountyAcreage [pw = pop1290new], robust beta
outreg2 * using "FinalTables\table6_cols_4_6.xls", addtext(test,`X',wt,pop1290,ctrls,yes) keep(Plague*) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}
}
* Same but with a Z-score of the dependent variable
foreach X in DMVsper100Kacre_std {
reg `X' Plague_mortal lpop1290new lCountyAcreage [pw = pop1290new], robust beta
outreg2 * using "FinalTables\table6_cols_4_6.xls", addtext(test,all,wt,pop1290,ctrls,yes) keep(Plague*) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}
foreach Z in 10 {
foreach X in in`Z'd out`Z'd {
reg `X'_std Plague_mortal lpop1290new lCountyAcreage [pw = pop1290new], robust beta
outreg2 * using "FinalTables\table6_cols_4_6.xls", addtext(test,`X',wt,pop1290,ctrls,yes) keep(Plague*) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}
}

** COLUMN (7) **
reg chgurb13001750 Plague_mortal if county != "Cornwall" [iw = pop1290new], robust beta
outreg2 * using "FinalTables\table6_cols_7.xls", addtext(test,base,wt,yes,ctrls,no) keep(Plague*) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
* Same but with a Z-score of the dependent variable
reg chgurb13001750_std Plague_mortal if county != "Cornwall" [iw = pop1290new], robust beta
outreg2 * using "FinalTables\table6_cols_7.xls", addtext(test,base,wt,yes,ctrls,no) keep(Plague*) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

***************
*** TABLE 7 *** 
***************

use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165

* PANEL A *
foreach Y in tech {
foreach X in 10k {
reg changefor1400_`X'_2_`Y' mortality changepop1400 changepop13001400c [pw = pop1300] if year == 1400, robust 
outreg2 mortality using "FinalTables\table6.xls", keep(mortality) se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1400) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
reg changefor1500_`X'_2_`Y' mortality changepop13001500 changepop13001500c [pw = pop1300] if year == 1500, robust 
outreg2 mortality using "FinalTables\table6.xls", keep(mortality) se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1500) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1600_`X'_2_`Y' mortality changepop13001600 changepop13001600c [pw = pop1300] if year == 1600, robust 
outreg2 mortality using "FinalTables\table6.xls", keep(mortality) se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1600) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1700_`X'_2_`Y' mortality changepop13001700 changepop13001700c [pw = pop1300] if year == 1700, robust 
outreg2 mortality using "FinalTables\table6.xls", keep(mortality) se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1750) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1750_`X'_2_`Y' mortality changepop13001750 changepop13001750c [pw = pop1300] if year == 1750, robust 
outreg2 mortality using "FinalTables\table6.xls", keep(mortality) se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1750) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1300_`X'_2_`Y' mortality changepop1300 changepop12001300c [pw = pop1200] if year == 1300, robust 
outreg2 mortality using "FinalTables\table6.xls", keep(mortality) se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1200-1300) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}
}
* PANEL B * 
** Not controlling **
foreach Y in tech {
foreach X in 10k {
reg changefor1400_`X'_2_`Y' mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\table6.xls", se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1400) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1500_`X'_2_`Y' mortality [pw = pop1300] if year == 1500, robust
outreg2 mortality using "FinalTables\table6.xls", se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1500) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1600_`X'_2_`Y' mortality [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\table6.xls", se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1600) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1700_`X'_2_`Y' mortality [pw = pop1300] if year == 1700, robust
outreg2 mortality using "FinalTables\table6.xls", se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1700) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1750_`X'_2_`Y' mortality [pw = pop1300] if year == 1750, robust
outreg2 mortality using "FinalTables\table6.xls", se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1300-1800) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changefor1300_`X'_2_`Y' mortality [pw = pop1300] if year == 1300, robust
outreg2 mortality using "FinalTables\table6.xls", se tex(landscape) addtext(outcome, pct_`Y'_`X', year, 1200-1300) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}
}

***************
*** TABLE 8 ***
***************

use data_for_het, clear
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop1400_std mortality m_* ``Y'' [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\table8.xls", se tex(landscape) addtext(year, 1400) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes replace
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\table8.xls", se tex(landscape) addtext(year, 1500) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\table8.xls", se tex(landscape) addtext(year, 1600) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\table8.xls", se tex(landscape) addtext(year, 1700) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\table8.xls", se tex(landscape) addtext(year, 1750) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13002015min_std mortality m_* ``Y'' [pw = pop1300] if year == 1850, robust beta
outreg2 * using "FinalTables\table8.xls", se tex(landscape) addtext(year, 2015min) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}

************************
*** APPENDIX TABLE 2 *** 
************************

use finaljjk4, clear
drop sample
keep if samplemort == 1

*** DRAFT: ALSO DROPPING MESSINA ***
foreach X of varlist euromena1_wl_euclidean {
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly3 "longitude2 latitude2 longitude3 latitude3"
* MESSINA * 
reg mortality `geo' `ecogeo' `pol' `poly3' messina_euclidean `X' [pw = pop1300] if year == 1400 & city_jjk != "MESSINA", robust cluster(entity1300) 
outreg2 *_euclidean using "FinalTables\tableA2.xls", keep(*_euclidean) addtext(yr,1400,ctrl,`X') br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel replace
* GENOVA * 
reg mortality `geo' `ecogeo' `pol' `poly3' genoa_euclidean `X' [pw = pop1300] if year == 1400 & city_jjk != "GENOVA" & city_jjk != "MESSINA", robust cluster(entity1300) 
outreg2 *_euclidean using "FinalTables\tableA2.xls", keep(*_euclidean) addtext(yr,1400,ctrl,`X') br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* VIENNA * 
reg mortality `geo' `ecogeo' `pol' `poly3' vienna_euclidean `X' [pw = pop1300] if year == 1400 & city_jjk != "WIEN" & city_jjk != "MESSINA", robust cluster(entity1300) 
outreg2 *_euclidean using "FinalTables\tableA2.xls", keep(*_euclidean) addtext(yr,1400,ctrl,`X') br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* PRAGUE * 
reg mortality `geo' `ecogeo' `pol' `poly3' prague_euclidean `X' [pw = pop1300] if year == 1400 & city_jjk != "PRAHA" & city_jjk != "MESSINA", robust cluster(entity1300) 
outreg2 *_euclidean using "FinalTables\tableA2.xls", keep(*_euclidean) addtext(yr,1400,ctrl,`X') br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* LEIPZIG * 
reg mortality `geo' `ecogeo' `pol' `poly3' leipzig_euclidean `X' [pw = pop1300] if year == 1400 & city_jjk != "LEIPZIG" & city_jjk != "MESSINA", robust cluster(entity1300) 
outreg2 *_euclidean using "FinalTables\tableA2.xls", keep(*_euclidean) addtext(yr,1400,ctrl,`X') br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* VISBY * 
reg mortality `geo' `ecogeo' `pol' `poly3' visby_euclidean `X' [pw = pop1300] if year == 1400 & city_jjk != "VISBY" & city_jjk != "MESSINA", robust cluster(entity1300) 
outreg2 *_euclidean using "FinalTables\tableA2.xls", keep(*_euclidean) addtext(yr,1400,ctrl,`X') br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
}

************************
*** APPENDIX TABLE 3 ***
************************

use finaljjk4, clear

*** WITHOUT CONTROLS ***
foreach X in speed2 {
foreach Y in 38 {
gen MA = lma1300_`X'_`Y'
reg mortality MA if year == 1400 & sample == 1, robust
outreg2 MA using "FinalTables\tableA3.xls", addtext(test, `Y') keep(MA) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
drop MA
}
}
foreach X in speed2 {
foreach Y in 2 1 {
gen MA = lma1300_`X'_`Y'
reg mortality MA if year == 1400 & sample == 1, robust
outreg2 MA using "FinalTables\tableA3.xls", addtext(test, `Y') keep(MA) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop MA
}
}
foreach X in speed1 dist {
foreach Y in 38 {
gen MA = lma1300_`X'_`Y'
reg mortality MA if year == 1400 & sample == 1, robust
outreg2 MA using "FinalTables\tableA3.xls", addtext(test, `X') keep(MA) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop MA
}
}
foreach Z in ownnew east10 both {
foreach X in speed2 {
foreach Y in 38 {
gen MA = lma1300`Z'_`X'_`Y'
reg mortality MA if year == 1400 & sample == 1, robust
outreg2 MA using "FinalTables\tableA3.xls", addtext(test, `Z') keep(MA) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop MA
}
}
}

*** WITH CONTROLS ***
foreach X in speed2 {
foreach Y in 38 2 1 {
gen MA = lma1300_`X'_`Y'
local ecogeo "lpop1300 MA DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
reg mortality `geo' `ecogeo' `pol' if year == 1400 & sample == 1, robust
outreg2 MA using "FinalTables\tableA3.xls", addtext(test, `Y') keep(MA) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop MA
}
}
foreach X in speed1 dist {
foreach Y in 38 {
gen MA = lma1300_`X'_`Y'
local ecogeo "lpop1300 MA DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
reg mortality `geo' `ecogeo' `pol' if year == 1400 & sample == 1, robust
outreg2 MA using "FinalTables\tableA3.xls", addtext(test, `X') keep(MA) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop MA
}
}
foreach Z in ownnew east10 both {
foreach X in speed2 {
foreach Y in 38 {
gen MA = lma1300`Z'_`X'_`Y'
local ecogeo "lpop1300 MA DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
reg mortality MA `geo' `ecogeo' `pol' if year == 1400 & sample == 1, robust
outreg2 MA using "FinalTables\tableA3.xls", addtext(test, `Z') keep(MA) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop MA
}
}
}

************************
*** APPENDIX TABLE 4 ***
************************

use finaljjk4, clear
drop sample
keep if samplemort == 1

* COL (1) 
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly3 "longitude2 latitude2 longitude3 latitude3"
xi: ivreg2 mortality `geo' `ecogeo' `pol' `poly3' messina_euclidean euromena1_wl_euclidean [pw = pop1300] if year == 1400 & city_jjk != "NEW-ROSS" & city_jjk != "MESSINA", robust cluster(entity1300) 
outreg2 mortality using "FinalTables\tableA4.xls", keep(messina_euclidean) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel replace
* COL (2) 
foreach X in 1 2 3 4 5 6 7 8 9 10 11 {
gen month_`X' = (start_month_35 == `X'+0.5)
tab month_`X'
}
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 lma1300_speed2_38 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly2 "longitude2 latitude2"
local poly3 "longitude2 latitude2 longitude3 latitude3"
local poly4 "longitude2 latitude2 longitude3 latitude3 longitude4 latitude4"
xi: ivreg2 mortality `geo' `ecogeo' `pol' `poly3' month_* i.start_year [pw = pop1300] if year == 1400, robust cluster(entity1300) 
outreg2 mortality using "FinalTables\tableA4.xls", keep(month_*) br se nocons coefastr bdec(1) sdec(1) rdec(2) noni nolabel 

************************
*** APPENDIX TABLE 5 ***
************************

use finaljjk4, clear 
keep if samplemort == 1 & mortality != .
count if year == 1300
drop changepop
sort countrycity year
bysort countrycity: gen changepop=(pop-pop[_n-1])/pop[_n-1]*100
bysort countrycity: gen lag1lpop=lpop[_n-1]
bysort countrycity: gen lag1pop=pop[_n-1]
* We create the mortality*year interactions
gen mortality1200 = 0
replace mortality1200 = mortality if year == 1200
gen mortality1300 = 0
replace mortality1300 = mortality if year == 1300
gen mortality1400 = 0
replace mortality1400 = mortality if year == 1400
gen mortality1500 = 0
replace mortality1500 = mortality if year == 1500
gen mortality1600 = 0
replace mortality1600 = mortality if year == 1600
gen mortality1700 = 0
replace mortality1700 = mortality if year == 1700
gen mortality1750 = 0
replace mortality1750 = mortality if year == 1750

* Coefficients for Figure 4
** NON-PANEL **
drop sample
xi: reg changepop mortality1200-mortality1750 i.year [pw = lag1pop] if year >= 1200 & year <= 1750, robust cluster(countrycity)
gen sample = e(sample)
outreg2 mortality* using "FinalTables\tableA5.xls", addtext(wgt, 1100) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
* PANEL *
drop sample
xi: areg changepop mortality1200-mortality1700 i.year [pw = lag1pop] if year >= 1200 & year <= 1750, robust absorb(countrycity) cluster(countrycity)
gen sample = e(sample)
outreg2 mortality* using "FinalTables\tableA5.xls", addtext(wgt, 1100) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
* PANEL WITH LOG *
sort countrycity year
gen chglpop = lpop-lag1lpop
replace chglpop = chglpop*100
xi: areg chglpop mortality1200-mortality1700 i.year [pw = lag1pop] if year >= 1200 & year <= 1750, robust absorb(countrycity) cluster(countrycity)
outreg2 mortality* using "FinalTables\tableA5.xls", addtext(wgt, 1100) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

************************
*** APPENDIX TABLE 6 ***
************************

* Row 1: Baseline *
use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust beta
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* Row 2: Dropping outliers *
use finaljjk4, clear
keep if samplemort == 1 
count if year == 1300
* 165
sum mortality, d
drop if mortality <= 10 | mortality >= 66
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust 
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, keepoutliers10) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, keepoutliers10) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* Row 3: Dropping hygienic *
use finaljjk4, clear
keep if samplemort == 1 
count if year == 1300
* 165
sum mortality, d
gen hygienic2 = (city_jjk == "MILANO" | city_jjk == "VENEZIA" | city_jjk == "NUERNBERG" | city_jjk == "BATH")
drop if hygienic2 == 1
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust beta
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* Row 4: Plague controls *
use finaljjk4, clear 
keep if samplemort == 1 & mortality != .
count if year == 1300
foreach X in 50 {
reg changepop1400 mortality reoccur`X'_1400_yn reoccur`X'_1400_sum if year == 1400 [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, biraben`X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality reoccur`X'_1600_yn reoccur`X'_1600_sum if year == 1600 [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, biraben`X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

** Rows 5-7: Battles controls **

use finaljjk4, clear

* Row 5
foreach X in 50 {
reg changepop1400 mortality battle`X'_1400_yn battle`X'_1400_sum if year == 1400 [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA6.xls", keep(mortality) addtext(test, battle`X') se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality battle`X'_1600_yn battle`X'_1600_sum if year == 1600 [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA6.xls", keep(mortality) addtext(test, battle`X') se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

* Row 6: Battles controls 2 *
foreach X in 50 {
reg changepop1400 mortality dist2bat13001352_100 battle100_1352_sum battle`X'_1400_yn battle`X'_1400_sum if year == 1400 [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, battle`X') se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality dist2bat13001352_100 battle100_1352_sum battle`X'_1600_yn battle`X'_1600_sum if year == 1600 [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, battle`X') se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

* Row 7: Battles controls 3 *
foreach X in 50 {
reg changepop1400 mortality battle50_100yrwar_1347_yn battle50_100yrwar_1347_sum if year == 1400 [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, battle`X') se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality battle50_100yrwar_1352_yn battle50_100yrwar_1352_sum if year == 1600 [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, battle`X') se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

* Row 8: Famines controls 1 *
* Row 9: Famines controls 2 *
use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165

* 1353-1400
reg changepop1400 mortality fam_13531400 [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
reg changepop1400 mortality fam_13531400 fam_13001352 [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
* 1353-1600
reg changepop13001600 mortality fam_13531600 [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 
reg changepop13001600 mortality fam_13531600 fam_13001352 [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) 

* Row 10: Wetness controls 1 *
* Row 11: Wetness controls 2 *
use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165

* 1300-1400
reg changepop1400 mortality extrawet131416 [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop1400 mortality wet131416_*moist [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
* 1300-1600
reg changepop13001600 mortality extrawet131416 [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality wet131416_*moist [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA6.xls", se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 12: Persecutions controls 1 **
** Row 13: Persecutions controls 2 **

use finaljjk4, clear 
keep if samplemort == 1 & mortality != .
count if year == 1300

* Row 12 *
reg changepop1400 mortality jewpresbd jewpersbd bdpogrom_yn_x bdexpulsion_yn_x if year == 1400 [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, jewpers) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality jewpresbd jewpersbd bdpogrom_yn_x bdexpulsion_yn_x if year == 1600 [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, jewpers) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* Row 13 *
reg changepop1400 mortality if year == 1400 & bdpogrom_yn_x == 0 & bdexpulsion_yn_x == 0 [pw = pop1300], robust beta
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, jewpers) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality if year == 1600 & bdpogrom_yn_x == 0 & bdexpulsion_yn_x == 0 [pw = pop1300], robust beta
outreg2 mortality using "FinalTables\tableA6.xls", addtext(test, jewpers) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Rows 14-15 **

use finaljjk4, clear
drop sample
keep if samplemort == 1

local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 lma1300_speed2_38 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly3 "longitude2 latitude2 longitude3 latitude3"
* 1400
xi: ivreg2 changepop1400 `geo' `ecogeo' `pol' `poly3' (mortality = i.start_month_35) i.start_year [pw = pop1300] if year == 1400, robust gmm2s cluster(entity1300) first 
outreg2 mortality using "FinalTables\tableA6.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* 1600
xi: ivreg2 changepop13001600 `geo' `ecogeo' `pol' `poly3' (mortality = i.start_month_35) i.start_year [pw = pop1300] if year == 1600, robust gmm2s cluster(entity1300) first
outreg2 mortality using "FinalTables\tableA6.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* IV F-stat: 6.0

* Row 15: IB2 *
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 lma1300_speed2_38 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly3 "longitude2 latitude2 longitude3 latitude3"

* 1400
sum avtemp15001600 if year == 1400, d
gen lavtemp15001600 = log(avtemp15001600)
tab start_month_35
foreach X of numlist 1(1)12 {
gen month_temp_`X' = 0
replace month_temp_`X' = lavtemp15001600 if start_month_35 == `X'+0.5
}
desc month_temp_*
xi: ivreg2 changepop1400 `geo' `ecogeo' `pol' `poly3' (mortality = month_temp_*) i.start_year [pw = pop1300] if year == 1400, robust gmm2s cluster(entity1300) first 
outreg2 mortality using "FinalTables\tableA6.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* 1600
xi: ivreg2 changepop13001600 `geo' `ecogeo' `pol' `poly3' (mortality = month_temp_*) i.start_year [pw = pop1300] if year == 1600, robust gmm2s cluster(entity1300) first
outreg2 mortality using "FinalTables\tableA6.xls", keep(mortality) br se nocons coefastr bdec(2) sdec(2) rdec(2) noni nolabel 
* IV F-stat: 6.6

************************
*** APPENDIX TABLE 7 ***
************************

use finaljjk4, clear 
keep if samplemort == 1 & mortality != .

foreach X in 50 {
reg mortality reoccur`X'_1400_yn reoccur`X'_1400_sum if year == 1400 [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA7.xls", addtext(test, biraben`X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
reg mortality reoccur`X'_1600_yn reoccur`X'_1600_sum if year == 1600 [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA7.xls", addtext(test, biraben`X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

************************
*** APPENDIX TABLE 8 *** 
************************

use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165
sort countrycity year
tab mortality_type if year == 1400
bysort mortality_type: tab mortality_info if year == 1400

** Row 1 **
xi: reg changepop1400 mortality [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
xi: reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 2 **
bysort city_id: egen maxchangepop12001300 = max(changepop12001300)
xi: reg changepop1400 mortality maxchangepop12001300 [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
xi: reg changepop13001600 mortality maxchangepop12001300 [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 3 **
gen changeabspop1400 = exp(lpop1400)-exp(lpop1300)
reg changeabspop1400 mortality  [pw = pop1300] if year == 1400, robust
gen changeabspop13001600 = exp(lpop1600)-exp(lpop1300)
reg changeabspop13001600 mortality  [pw = pop1300] if year == 1600, robust
gen abspoploss = pop1300/100*mortality
reg changeabspop1400 abspoploss  [pw = pop1300] if year == 1400, robust
reg changeabspop13001600 abspoploss [pw = pop1300] if year == 1600, robust
reg changeabspop1400 abspoploss pop1300 [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changeabspop13001600 abspoploss pop1300 [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 4 **
use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust cluster(entity1300) 
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, SEstate) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust cluster(entity1300)
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, SEstate) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 5 **
foreach Z in 500 {
acreg changepop1400 mortality  [pw = pop1300] if year == 1400, spatial dist(`Z') latitude(latitude) longitude(longitude) 
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
acreg changepop13001600 mortality  [pw = pop1300] if year == 1600, spatial dist(`Z') latitude(latitude) longitude(longitude) 
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

** Row 6 **
xi: reg changepop1400 mortality i.mortality_type [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
xi: reg changepop13001600 mortality i.mortality_type [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, dummytype) se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 7 **
reg changepop1400 mortality [pw = pop1300] if year == 1400 & mortality_type != "Description", robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, dropdescription) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600 & mortality_type != "Description", robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, dropdescription) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 8 **
reg changepop1400 mortality [pw = pop1300] if year == 1400 & mortality_type != "Desertion", robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, dropdesertion) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600 & mortality_type != "Desertion", robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, dropdesertion) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 9 **
reg changepop1400 mortality [pw = pop1300] if year == 1400 & mortality_type != "Clergy", robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, dropclergy) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600 & mortality_type != "Clergy", robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, dropclergy) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 10 **
reg changepop1400 mortality_raw [pw = pop1300] if year == 1400, robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, raw) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality_raw [pw = pop1300] if year == 1600, robust
outreg2 mortality* using "FinalTables\tableA8.xls", addtext(test, raw) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 11 **
use finaljjk4, clear
keep if samplemort == 1 
count if year == 1300
* 165
sum mortality, d
keep if mortality <= 16.66667 | mortality >= 60
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust 
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, keepoutliers10) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, keepoutliers10) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 12 **
use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165
gen mortcat_0_25 = (mortality >=0 & mortality <25)
gen mortcat_25_50 = (mortality >=25 & mortality <50)
gen mortcat_50_75 = (mortality >=50 & mortality <75)
gen mortcat_75_100 = (mortality >=75 & mortality <100)
reg changepop1400 mortcat_25-mortcat_75 [pw = pop1300] if year == 1400, robust
outreg2 mortcat_25-mortcat_75 using "FinalTables\tableA8.xls", addtext(test, baseline) sideway se tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortcat_25-mortcat_75 [pw = pop1300] if year == 1600, robust
outreg2 mortcat_25-mortcat_75 using "FinalTables\tableA8.xls", addtext(test, baseline) sideway se tex(landscape) nocons coefastr dec(1) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop mortcat* 

** Rows 13-14 **
use finaljjk4, clear
keep if samplemort == 1
count if year == 1300
* 165
gen pop_b_300 = pop_bairoch if year == 1300
bysort countrycity: egen pop_b_1300 = max(pop_b_300)
drop pop_b_300
sort countrycity year
bysort countrycity: gen changepop_b_1400=(pop_bairoch-pop_bairoch[_n-1])/pop_bairoch[_n-1]*100 if year == 1400
bysort countrycity: gen changepop_b_13001600=(pop_bairoch-pop_bairoch[_n-3])/pop_bairoch[_n-3]*100 if year == 1600
drop pop*1*00c changepop1300*c
gen pop_c_300 = chandlerpop if year == 1300
bysort countrycity: egen pop1300c = max(pop_c_300)
drop pop_c_300
gen pop_c_400 = chandlerpop if year == 1400
bysort countrycity: egen pop1400c = max(pop_c_400)
drop pop_c_400
gen pop_c_600 = chandlerpop if year == 1600
bysort countrycity: egen pop1600c = max(pop_c_600)
drop pop_c_600
foreach X in 1400 1600 {
gen changepop1300`X'c = (pop`X'c-pop1300c)/pop1300c*100
}

* Row 13
reg changepop_b_1400 mortality [pw = pop_b_1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, bairoch) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop_b_13001600 mortality [pw = pop_b_1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, bairoch) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
* Row 14
reg changepop13001400c mortality [pw = pop_c_1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, chandler) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600c mortality [pw = pop_c_1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, chandler) sideway se nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* Row 15
use finaljjk4, clear
foreach X in 50 {
gen mortality_new_`X' = mortality
replace mortality_new_`X' = mortality_`X' if mortality == . & mortality_`X' !=.
}
foreach X in 50 {
reg changepop1400 mortality_new_`X' [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, nearest`X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality_new_`X' [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, nearest`X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

* Row 16
use finaljjk4, clear
replace mortality = mortality_state if mortality == . 
reg changepop1400 mortality [pw = pop1300] if year == 1400, robust cluster(entity1300)
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, mortstate) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust cluster(entity1300)
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, mortstate) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

* Row 17
use finaljjk4, clear
reg changepop1400 mortality274 [pw = pop1300] if year == 1400, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, extrap274) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality274 [pw = pop1300] if year == 1600, robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, extrap274) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

** Row 18 **

*  We have to create the weights for the reweighting.

* Distribution in the full sample of cities existing in 1300. 
use finaljjk4, clear
keep if year == 1300
count
keep if pop1300 != . & pop1300 != .
count
* 466
sum pop1300
* from 1 to 228 
replace pop1300 = round(pop1300,1)
gen pop1300str = string(pop1300)
order pop1300str
gsort- pop1300
gen popthous = "0" if pop1300 < 10
replace popthous = substr(pop1300str,1,1) if pop1300 >= 10 & pop1300 < 100
replace popthous = substr(pop1300str,1,2) if pop1300 >= 100
destring popthous, replace
tab popthous
gen count = 1
collapse (sum) count, by(popthous)
egen sumcount = sum(count)
gen share_full = count/sumcount
keep popthous share_full
sort popthous
save dist_full, replace

* Distribution in our main sample. 
use finaljjk4, clear
keep if year == 1300
count
keep if pop1300 != . & pop1300 != .
count
* 466
sum pop1300
keep if mortality != .
count
* 165
* from 1 to 228 
replace pop1300 = round(pop1300,1)
gen pop1300str = string(pop1300)
order pop1300str
gsort- pop1300
gen popthous = "0" if pop1300 < 10
replace popthous = substr(pop1300str,1,1) if pop1300 >= 10 & pop1300 < 100
replace popthous = substr(pop1300str,1,2) if pop1300 >= 100
destring popthous, replace
tab popthous
gen count = 1
collapse (sum) count, by(popthous)
egen sumcount = sum(count)
gen share_main = count/sumcount
keep popthous share_main
sort popthous
save dist_main, replace 

* We merge and create the correction. 
use dist_full, clear
sort popthous 
merge popthous using dist_main
tab _m
drop _m
*twoway (connected share_full popthous) (connected share_main popthous), legend(order(1 "Full sample" 2 "Main sample"))
gen correction = share_full/share_main
*twoway (connected correction popthous) 
keep popthous correction
sort popthous
save correction, replace

* Regression
use finaljjk4, clear
count
keep if pop1300 != . & pop1300 != .
keep if mortality != .
count
* 165
gen pop1300_2 = round(pop1300,1)
gen pop1300str = string(pop1300_2)
order pop1300str
gsort- pop1300_2
gen popthous = "0" if pop1300_2 < 10
replace popthous = substr(pop1300str,1,1) if pop1300_2 >= 10 & pop1300_2 < 100
replace popthous = substr(pop1300str,1,2) if pop1300_2 >= 100
destring popthous, replace
sort popthous
merge popthous using correction
tab _m
drop if _m == 2
drop _m
codebook correction
gen new_wt = pop1300 * correction

reg changepop1400 mortality if year == 1400 [pw = new_wt], robust 
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, rewt) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality if year == 1600 [pw = new_wt], robust
outreg2 mortality using "FinalTables\tableA8.xls", addtext(test, rewt) sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append

*************************
*** APPENDIX TABLE A9 ***
*************************

use finaljjk4, clear
count
keep if pop1300 != . & pop1300 != .
keep if mortality != .
count
* 165
replace countryname = "UK" if countryname == "United Kingdom"
reg changepop1400 mortality if year == 1400 [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA9.xls", addtext(test, wo `X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
reg changepop13001600 mortality if year == 1600 [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA9.xls", addtext(test, wo `X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
foreach X in France Germany Italy UK Spain {
reg changepop1400 mortality if year == 1400 & countryname != "`X'" [pw = pop1300], robust 
outreg2 mortality using "FinalTables\tableA9.xls", addtext(test, wo `X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
reg changepop13001600 mortality if year == 1600 & countryname != "`X'" [pw = pop1300], robust
outreg2 mortality using "FinalTables\tableA9.xls", addtext(test, wo `X') sideway se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
}

**************************
*** APPENDIX TABLE A10 ***
**************************

use finaljjk4, clear
keep if samplemort == 1
count
* 165
drop sample
* By distance
foreach X in 86 219 332 {
sort city_id
merge city_id using shock_dist_`X'_274
tab _m
drop if _m == 2
drop _m
}

* 1400 *
foreach X in 86 {
gen test = mortdist`X'
reg changepop1400 mortality test [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes replace
drop test
foreach N in 25 50 {
gen test = mortdist`X'_no`N'
reg changepop1400 mortality test [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes 
drop test
}
}
foreach X in 219 332 {
gen test = mortdist`X'
reg changepop1400 mortality test [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes 
drop test
foreach N in 25 50 {
gen test = mortdist`X'_no`N'
reg changepop1400 mortality test [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes 
drop test
}
}
gen sample = e(sample)
foreach X in changepop1400 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen Z = (`X'-mean)/std if sample == 1
}
drop mean std sample
foreach X in 86 219 332 {
gen test = mortdist`X'
reg Z mortality test [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop test
foreach N in 25 50 {
gen test = mortdist`X'_no`N'
reg Z mortality test [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop test
}
}
drop Z 

* 1300-1600 *
foreach X in 86 219 332 {
gen test = mortdist`X'
reg changepop13001600 mortality test [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes 
drop test
foreach N in 25 50 {
gen test = mortdist`X'_no`N'
reg changepop13001600 mortality test [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes 
drop test
}
}
gen sample = e(sample)
foreach X in changepop13001600 {
egen mean = mean(`X') if sample == 1
egen std = sd(`X') if sample == 1
gen Z = (`X'-mean)/std if sample == 1
}
drop mean std sample
foreach X in 86 219 332 {
gen test = mortdist`X'
reg Z mortality test [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop test
foreach N in 25 50 {
gen test = mortdist`X'_no`N'
reg Z mortality test [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA10.xls", se addtext(dist, "`X'", dist2, "`N'") tex(landscape) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop test
}
}
drop Z

**************************
*** APPENDIX TABLE A11 ***
**************************

* We modify the country name and add the EMP variables
use finaljjk4, clear
codebook countryname
tab countryname
keep if samplemort == 1
count if year == 1300
* 165
sort city_jjk
merge city_jjk using countryname2
tab _m
drop _m
sort countryname2
merge countryname2 using emp_data
tab _m
drop _m

* We create the main variables.
* These are the North variables. 
gen N_all = (countryname == "Belgium" | countryname == "Denmark" | countryname == "Germany" | countryname == "Ireland"  | countryname == "Luxembourg"  | countryname == "Norway" | countryname == "Sweden" | countryname == "The Netherlands"  | countryname == "United Kingdom" | countryname == "France" | countryname == "Austria" | countryname == "Switzerland")
gen N_nofr = (countryname == "Belgium" | countryname == "Denmark" | countryname == "Germany" | countryname == "Ireland"  | countryname == "Luxembourg"  | countryname == "Norway" | countryname == "Sweden" | countryname == "The Netherlands"  | countryname == "United Kingdom" | countryname == "Austria" | countryname == "Switzerland")
* These are the variables based on the age at marriage and celibacy
sum age_1st_mar if year == 1300, d
gen emp_mar_abovmean = (age_1st_mar > 24.79576)
gen emp_mar_abovmed = (age_1st_mar > 25.2)
sum celibacy if year == 1300, d
gen emp_cel_abovmean = (celibacy > 12.99879)
gen emp_cel_abovmed = (celibacy > 11.5)

reg changepop13001600 mortality [pw = pop1300] if year == 1600, robust beta
outreg2 mortality using "FinalTables\tableA11.xls", keep(mortality) se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) replace
foreach X of varlist N_all N_nofr emp_* {
gen mort_North = 0
replace mort_North = mortality if `X' == 1
gen North = `X' 
reg changepop13001600 mortality North mort_North [pw = pop1300] if year == 1600, robust beta
outreg2 mortality using "FinalTables\tableA11.xls", keep(mortality North mort_North) addtext(north, `X') se tex(landscape) nocons coefastr dec(2) noni nolabel bracket title(Effect, "") nonotes addnote("", Robust standard errors clustered at the district level in parentheses, * significant at 10%; ** significant at 5%; *** significant at 1%) append
drop mort_North North
}

**************************
*** APPENDIX TABLE A12 ***
**************************

use data_for_het, clear
local agri "invcerealclosest potatolowclosest pastoral_weak_closest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop1400 mortality m_* ``Y'' [pw = pop1300] if year == 1400, robust beta
outreg2 * using "FinalTables\tableA12.xls", se tex(landscape) addtext(year, 1400) keep(m_* mortality) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes replace 
reg changepop13001500 mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA12.xls", se tex(landscape) addtext(year, 1500) keep(m_* mortality) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600 mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA12.xls", se tex(landscape) addtext(year, 1600) keep(m_* mortality) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700 mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA12.xls", se tex(landscape) addtext(year, 1700) keep(m_* mortality) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750 mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA12.xls", se tex(landscape) addtext(year, 1750) keep(m_* mortality) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13002015min mortality m_* ``Y'' [pw = pop1300] if year == 1850, robust beta
outreg2 * using "FinalTables\tableA12.xls", se tex(landscape) addtext(year, 2015min) keep(m_* mortality) nocons coefastr dec(1) sdec(1) bdec(1) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}

**************************
*** APPENDIX TABLE A13 ***
**************************

use data_for_het, clear
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
areg changepop1400_std mortality m_* ``Y'' [pw = pop1300] if year == 1400, robust absorb(countryname)
outreg2 * using "FinalTables\tableA13.xls", se tex(landscape) addtext(year, 1400) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes replace
areg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust absorb(countryname)
outreg2 * using "FinalTables\tableA13.xls", se tex(landscape) addtext(year, 1500) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
areg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust absorb(countryname)
outreg2 * using "FinalTables\tableA13.xls", se tex(landscape) addtext(year, 1600) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
areg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust absorb(countryname)
outreg2 * using "FinalTables\tableA13.xls", se tex(landscape) addtext(year, 1700) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
areg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust absorb(countryname)
outreg2 * using "FinalTables\tableA13.xls", se tex(landscape) addtext(year, 1750) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
areg changepop13002015min_std mortality m_* ``Y'' [pw = pop1300] if year == 1850, robust absorb(countryname)
outreg2 * using "FinalTables\tableA13.xls", se tex(landscape) addtext(year, 2015min) keep(m_* mortality) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}

**************************
*** APPENDIX TABLE A14 ***
**************************

** ROWS 1-3: COAST **

* Additional information on estuaries. 
* We collected ourselves using Google Map. 
* Wide = estuary. * Small = non-estuary. 
clear
import excel "riversea_02162020.xlsx", sheet("Sheet1") firstrow clear
keep city_id directsea riversea_wide riversea_small
sort city_id
save directsea, replace

use data_for_het, clear
sort city_id
merge city_id using directsea
tab _m
drop _m
* We modify some of the variables. 
foreach X in directsea riversea_wide riversea_small {
replace `X' = 0 if `X' == .
}
gen directsea_wide = (directsea == 1 | riversea_wide == 1)
replace dist2AMNB_50 = 0 if directsea == 0 & riversea_wide == 0 & riversea_small == 0
* Atlantic ocean including the North-Baltic sea*
replace dist2A_10 = 1 if dist2NB_10 == 1
replace dist2A_50 = 1 if dist2NB_50 == 1
foreach N in 10 50 {
foreach Z in AMNB M A {
foreach X in directsea directsea_wide riversea_wide riversea_small {
gen `X'_`Z'_`N' = 0
replace `X'_`Z'_`N' = 1 if `X' == 1 & dist2`Z'_`N' == 1
}
}
}
* River, not estuary
gen rivernosea_all = (river == 1 & directsea_AMNB_10 == 0 & riversea_wide_AMNB_50 == 0)

** ROW 1 **
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls' directsea_AMNB_10 riversea_wide_AMNB_50 rivernosea_all"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1500) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes replace 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1600) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1700) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1750) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}

** ROW 2 **
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls' directsea_wide_M_50 directsea_wide_A_50 rivernosea_all"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1500) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1600) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1700) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1750) keep(m_*sea*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}

** ROW 3 **
* For this one, we use another definition of rivers without access to the sea
drop rivernosea_all
gen rivernosea_all = (river == 1 & directsea_wide_AMNB_50 == 0)
* Interactions for monarchy and coast 
gen wide50_mon = (directsea_wide_AMNB_50 == 1 & monarchy == 1)
gen wide50_nonmon = (directsea_wide_AMNB_50 == 1 & monarchy == 0)
* Interactions for monarchy and river
gen rivno50_mon = (rivernosea_all == 1 & monarchy == 1)
gen rivno50_nonmon = (rivernosea_all == 1 & monarchy == 0)
* We create the other monarchy variable
gen mon_other = 0
replace mon_other = monarchy if directsea_wide_AMNB_50 == 0 & rivernosea_all == 0
sum wide50_mon wide50_nonmon rivno50_mon rivno50_nonmon mon_other if year == 1850

local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "rd_int HansaFixed"
local ctrls "lpop1353 Bcapital representative1300" 
local all "`agri' `trade' `ctrls' wide50_mon wide50_nonmon rivno50_mon rivno50_nonmon mon_other"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1500) keep(m_*sea* m_*mon*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1600) keep(m_*sea* m_*mon*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1700) keep(m_*sea* m_*mon*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_1_3.xls", se tex(landscape) addtext(year, 1750) keep(m_*sea* m_*mon*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}

** ROW 4: LOG POP 1300 **

foreach Z in lpop1300 {
use data_for_het, clear
gen lpop1353sq = lpop1353*lpop1353
local agri "invcerealclosest potatolowclosest pastoral_weak_closest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353 monarchy Bcapital representative1300" 
local test "`Z'"
local all "`agri' `trade' `ctrls' `test'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1500) keep(m_lpop1300) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes replace
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1600) keep(m_lpop1300) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1700) keep(m_lpop1300) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1750) keep(m_lpop1300) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 5: MARKET ACCESS **

* We use 1353 but could have used 1300
*foreach Z in lma1300_speed2_38 lma1353e_speed2_38 {
foreach Z in lma1353e_speed2_38 {
use data_for_het, clear
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls' `Z'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) keep(m_lma*_speed2_38) addtext(year, 1500) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) keep(m_lma*_speed2_38) addtext(year, 1600) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) keep(m_lma*_speed2_38) addtext(year, 1700) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) keep(m_lma*_speed2_38) addtext(year, 1750) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 6: STATE POP SIZE **

* Number of cities and pop of cities by state 1353
use finaljjk4, clear
keep if year == 1300
count
gen citynum = (pop1353e != . & pop1353e >= 1)
gen citypop = pop1353e 
* We use entity1300_old so all small states of HRE are classified as "small states"
collapse (sum) citynum citypop, by(entity1300_old)
ren citynum citynum_state1353
ren citypop citypop_state1353
sort entity1300_old
save statesize1353, replace

use data_for_het, clear
* We add the size of the state
sort entity1300_old
merge entity1300_old using statesize1353
tab _m
drop if _m == 2
drop _m
gen lcitypop_state = log(citypop_state1353)
drop citypop*

foreach Z of varlist lcitypop_state  {
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "coast river `Z' rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1500) keep(m_lcitypop_state) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1600) keep(m_lcitypop_state) nocons coefastr dec(3)  noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1700) keep(m_lcitypop_state) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_4_6.xls", se tex(landscape) addtext(year, 1750) keep(m_lcitypop_state) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 7: GUILDS **

* Data set on guilds (see the Web Appendix for details)
import excel "Guilds_165_PPP_dummy.xlsx", sheet("Sheet1") firstrow clear
keep city_jjk guild*
gen guild1 = guild_pre_BD
egen guild2 = rmax(guild_pre_BD guild_by14th)
egen guild3 = rmax(guild_pre_BD guild_by14th guild_post_14th)
keep city_jjk guild1 guild2 guild3
sort city_jjk
save guilds, replace

use data_for_het, clear
sort city_jjk
merge city_jjk using guilds
tab _m
drop _m
sum guild2 if year == 1300
foreach Z in guild1 {
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300 `Z'"
local all "`agri' `trade' `ctrls'"
* STD
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1500) keep(m_guild*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes replace
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1600) keep(m_guild*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1700) keep(m_guild*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1750) keep(m_guild*) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 8: MARKET FAIR **

foreach Z in fair_all {
use data_for_het, clear
gen lpop1353sq = lpop1353*lpop1353
local agri "invcerealclosest potatolowclosest pastoral_weak_closest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353 monarchy Bcapital representative1300" 
local test "`Z'"
local all "`agri' `trade' `ctrls' `test'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1500) keep(m_fair_all) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1600) keep(m_fair_all) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1700) keep(m_fair_all) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_7_8.xls", se tex(landscape) addtext(year, 1750) keep(m_fair_all) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 9: WALL **

* Data set on walls
* See the Web Appendix for data sources
clear
import delimited "journal.pone.0162678.s003.CSV", clear 
tab urbansytem
gen city_jjk = upper(settlement)
replace city_jjk = "LONDON" if city_jjk == "LONDON & SOUTHWARK"
replace city_jjk = "AIX" if city_jjk == "AIX-EN-PROVENCE"
replace city_jjk = "BRUGGE" if city_jjk == "BRUGES"
replace city_jjk = "BURY-ST-EDMUNDS" if city_jjk == "BURY ST EDMUNDS"
replace city_jjk = "CARCASSONNE" if city_jjk == "CARCASSONE"
replace city_jjk = "FRANKFURTAMMAIN" if city_jjk == "FRANKFURT AM MAIN"
replace city_jjk = "GENEVE" if city_jjk == "GENEVA"
replace city_jjk = "GENT" if city_jjk == "GHENT"
replace city_jjk = "GREAT-YARMOUTH" if city_jjk == "GREAT YARMOUTH"
replace city_jjk = "HULL" if city_jjk == "KINGSTON-UPON-HULL"
replace city_jjk = "KING'SLYNN" if city_jjk == "KINGÂ’S LYNN"
replace city_jjk = "LEPUY" if city_jjk == "LE PUY"
replace city_jjk = "MANTUA" if city_jjk == "MANTOVA"
replace city_jjk = "MARSEILLE" if city_jjk == "MARSEILLES"
replace city_jjk = "MECHELEN" if city_jjk == "MECHLIN"
replace city_jjk = "REGGIONELL'EMILIA" if city_jjk == "REGGIO EMILIA"
replace city_jjk = "ST-OMER" if city_jjk == "SAINT-OMER"
replace city_jjk = "IEPER" if city_jjk == "YPRES"
replace city_jjk = "ZUERICH" if city_jjk == "ZURICH"
ren pop pop_lobo
ren area_sqkm area_lobo
keep city_jjk pop_lobo area_lobo urbansytem
replace pop_lobo = pop_lobo/1000
gen dens_lobo = pop_lobo/area_lobo
label var pop_lobo "Population ca 1300 in Lobo (000s)"
label var area_lobo "Area ca 1300 in Lobo (sq km)"
label var dens_lobo "Density ca 1300 in Lobo (000s per sq km)"
sort city_jjk
save land_area_lobo, replace

* We add to the main data set 
use data_for_het, clear
sort city_jjk
merge city_jjk using land_area_lobo
tab _m
keep if _m == 3
gen larea_lobo = log(area_lobo)

foreach Z in larea_lobo {
local agri "invcerealclosest potatolowclosest pastoral_weak_closest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1300 lpop1353 monarchy Bcapital representative1300" 
local test "`Z'"
local all "`agri' `trade' `ctrls' `test'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1500) keep(m_larea_lobo) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes replace
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1600) keep(m_larea_lobo) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1700) keep(m_larea_lobo) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1750) keep(m_larea_lobo) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 10: BISHOPRIC **

use data_for_het, clear
* We create the bishopric variable.
gen anyshopric2 = (bishopric2 == 1 | archbishopric2 == 1)
sum anyshopric2 if year == 1300
foreach Z in anyshopric2 {
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300" 
local all "`agri' `trade' `ctrls' `Z'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1500) keep(m_anyshopric2) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1600) keep(m_anyshopric2) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1700) keep(m_anyshopric2) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1750) keep(m_anyshopric2) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 11: UNIVERSITY **

foreach Z in university {
use data_for_het, clear
gen lpop1353sq = lpop1353*lpop1353
local agri "invcerealclosest potatolowclosest pastoral_weak_closest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353 monarchy Bcapital representative1300" 
local test "`Z'"
local all "`agri' `trade' `ctrls' `test'"

foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1500) keep(m_university) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1600) keep(m_university) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1700) keep(m_university) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1750) keep(m_university) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

** ROW 12: SERFDOM **

use data_for_het, clear
* We create the serfdom variable
gen serfdom = (countryname == "Germany" | countryname == "Czech Republic")
sum serfdom if year == 1300
foreach Z in serfdom {
local agri "invcerealclosest pastoral_weak_closest potatolowclosest"
local trade "coast river rd_int HansaFixed"
local ctrls "lpop1353  monarchy Bcapital representative1300 `Z'"
local all "`agri' `trade' `ctrls'"
foreach Y in all {
foreach X of local `Y' {
gen m_`X' = mortality * `X'
}
reg changepop13001500_std mortality m_* ``Y'' [pw = pop1300] if year == 1500, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1500) keep(m_serfdom) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001600_std mortality m_* ``Y'' [pw = pop1300] if year == 1600, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1600) keep(m_serfdom) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001700_std mortality m_* ``Y'' [pw = pop1300] if year == 1700, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1700) keep(m_serfdom) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
reg changepop13001750_std mortality m_* ``Y'' [pw = pop1300] if year == 1750, robust beta
outreg2 * using "FinalTables\tableA14_row_9_12.xls", se tex(landscape) addtext(year, 1750) keep(m_serfdom) nocons coefastr dec(3) noni nolabel bracket title(Effect, "") nonotes 
drop m_*
}
}

**************************
*** APPENDIX FIGURE A1 ***
**************************

* Created in the folder "Figure A1"

**************************
*** APPENDIX FIGURE A2 ***
**************************

use finaljjk4, clear
keep if samplemort == 1
twoway (kdensity duration if year == 1300, lcolor(black) lwidth(medthick)), ytitle(Kernel Density) ytitle(, margin(small)) xtitle(Duration of the Epidemic (Months)) xtitle(, margin(small)) xline(7, lwidth(medthick) lpattern(dash) lcolor(gs8)) xlabel(3(1)13) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
graph export "FinalFigures\figureA2.png", replace width(2620) height(1908)

**************************
*** APPENDIX FIGURE A3 ***
**************************

* Data on the spread of the Plague
use data_spread, clear
drop if lat >= 55
save data_spread2, replace

* Data created above when using IV1 *
use data_spread2, clear
* We add and trim the map of boundaries. 
append using boundaries
* We select Europe.
drop if _X != . & _X < -130
drop if _X != . & _X > 150
drop if _Y != . & _Y > 70
keep if (lon == . & _X > -15) | (lon != . & lon > -15)
keep if (lon == . & _X < 45) | (lon != . & lon < 45)
keep if (lat == . & _Y > 35) | (lat != . & lat > 35)
keep if (lat == . & _Y < 70) | (lat != . & lat <70)
keep if (lon == . & _X < 20) | (lon != .)
keep if (lon == . & _X >= -12) | (lon != .)
keep if (lon == . & _Y < 60) | (lat != .)
* We exclude some cities so that the map is smaller. 
keep if (lon == . & _Y < 55) | (lat != .)
keep if (lon == . & _X < 16.5) | (lon != .)
keep if (lon == . & _X > -9.5) | (lon != .)
keep if (lon == . & _Y > 35) | (lat != .)

** Months 0-2 **
gen citylegend = (city_jjk == "MESSINA" | city_jjk == "GENOVA" | city_jjk == "MARSEILLE" | city_jjk == "VENEZIA" | city_jjk == "BARCELONA" | city_jjk == "VALENCIA" | city_jjk == "NAPOLI")
foreach X of numlist 0 {
twoway (scatter _Y _X, mcolor(gs12) msize(vtiny) msymbol(circle) mlcolor(gs10) mlwidth(medthick))  ///
(scatter lat lon [w=pop1300], mcolor(gs10) msize(medsmall) msymbol(circle_hollow)) ///
(scatter lat lon if citylegend == 1, mcolor(white) msize(tiny) msymbol(point) mlabel(city_jjk) mlabcolor(black) mlabsize(small)) ///
(scatter lat lon if months_oct1347 < `X', mcolor(gs8) msize(large) msymbol(lgx) mlcolor(gs8) mlwidth(medthick)) ///
(scatter lat lon if months_oct1347 >= `X' & months_oct1347 <= (`X'+2), mcolor(black) msize(large) msymbol(circle)) ///
, legend(order(4 "Previously Impacted" 5 "Newly Impacted") row(1)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph export "FinalFigures\Figure3Aa.png", replace width(2620) height(1908)
}
drop citylegend
graph export "FinalFigures\Figure3Aa.png", replace width(2620) height(1908)

** Months 3-5 **
gen citylegend = (city_jjk == "BARCELONA" | city_jjk == "VALENCIA" | city_jjk == "NAPOLI" | city_jjk == "PALMA" | city_jjk == "LERIDA" | city_jjk == "AREZZO" | city_jjk == "LUCA" | city_jjk == "SIENA" | city_jjk == "ROMA")
foreach X of numlist 3 {
twoway (scatter _Y _X, mcolor(gs12) msize(vtiny) msymbol(circle) mlcolor(gs10) mlwidth(medthick))  ///
(scatter lat lon [w=pop1300], mcolor(gs10) msize(medsmall) msymbol(circle_hollow)) ///
(scatter lat lon if citylegend == 1, mcolor(white) msize(tiny) msymbol(point) mlabel(city_jjk) mlabcolor(black) mlabsize(small)) ///
(scatter lat lon if months_oct1347 < `X', mcolor(gs8) msize(large) msymbol(lgx) mlcolor(gs8) mlwidth(medthick)) ///
(scatter lat lon if months_oct1347 >= `X' & months_oct1347 <= (`X'+2), mcolor(black) msize(large) msymbol(circle)) ///
, legend(order(4 "Previously Impacted" 5 "Newly Impacted") row(1)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph export "FinalFigures\Figure3Ab.png", replace width(2620) height(1908)
}
drop citylegend
* Modify manually
graph export "FinalFigures\Figure3Ab.png", replace width(2620) height(1908)

** Months 6-8 **
gen citylegend = (city_jjk == "ROUEN" | city_jjk == "CORDOBA" | city_jjk == "LISBOA" | city_jjk == "BORDEAUX" | city_jjk == "LONDON")
foreach X of numlist 6 {
twoway (scatter _Y _X, mcolor(gs12) msize(vtiny) msymbol(circle) mlcolor(gs10) mlwidth(medthick))  ///
(scatter lat lon [w=pop1300], mcolor(gs10) msize(medsmall) msymbol(circle_hollow)) ///
(scatter lat lon if citylegend == 1, mcolor(white) msize(tiny) msymbol(point) mlabel(city_jjk) mlabcolor(black) mlabsize(small)) ///
(scatter lat lon if months_oct1347 < `X', mcolor(gs8) msize(large) msymbol(lgx) mlcolor(gs8) mlwidth(medthick)) ///
(scatter lat lon if months_oct1347 >= `X' & months_oct1347 <= (`X'+2), mcolor(black) msize(large) msymbol(circle)) ///
, legend(order(4 "Previously Impacted" 5 "Newly Impacted") row(1)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph export "FinalFigures\Figure3Ac.png", replace width(2620) height(1908)
}
drop citylegend
* Modify manually
graph export "FinalFigures\Figure3Ac.png", replace width(2620) height(1908)

** Months 9-11 **
gen citylegend = (city_jjk == "LONDON" | city_jjk == "PARIS" | city_jjk == "CORDOBA" | city_jjk == "BRISTOL" | city_jjk == "PLYMOUTH")
foreach X of numlist 9 {
twoway (scatter _Y _X, mcolor(gs12) msize(vtiny) msymbol(circle) mlcolor(gs10) mlwidth(medthick))  ///
(scatter lat lon [w=pop1300], mcolor(gs10) msize(medsmall) msymbol(circle_hollow)) ///
(scatter lat lon if citylegend == 1, mcolor(white) msize(tiny) msymbol(point) mlabel(city_jjk) mlabcolor(black) mlabsize(small)) ///
(scatter lat lon if months_oct1347 < `X', mcolor(gs8) msize(large) msymbol(lgx) mlcolor(gs8) mlwidth(medthick)) ///
(scatter lat lon if months_oct1347 >= `X' & months_oct1347 <= (`X'+2), mcolor(black) msize(large) msymbol(circle)) ///
, legend(order(4 "Previously Impacted" 5 "Newly Impacted") row(1)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 
graph export "Figure3Ad.png", replace width(2620) height(1908)
}
drop citylegend
* Modify manually
graph export "FinalFigures\Figure3Ad.png", replace width(2620) height(1908)

**************************
*** APPENDIX FIGURE A4 ***
**************************

use finaljjk4, clear 
keep if samplemort == 1
* We add the wal data
* See the Web Appendix for details on the sources
sort city_jjk
merge city_jjk using land_area_lobo
tab _m
keep if _m == 3
keep if area_lobo !=.
gen dens_lobo2 = pop1300/area_lobo
corr dens_lobo dens_lobo2
sum dens_lobo dens_lobo2
gen ldens_lobo = log(dens_lobo)
twoway (scatter mortality ldens_lobo, mcolor(black) msize(medsmall) msymbol(circle) mlabel(city_jjk) mlabsize(vsmall) mlabcolor(black)) (lfit mortality ldens_lobo, lcolor(black) lwidth(medthick) lpattern(dash)), ytitle(Black Death Mortality Rate (%) in 1347-1352) xtitle(Log Population Density in 1300) ytitle(, margin(medsmall)) xlabel(1.5(0.5)3.5) xtitle(, margin(medsmall)) legend(off) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ylabel(0(10)70)
graph export "FinalFigures\FigureA4.png", replace width(2620) height(1908)
reg mortality ldens_lobo if year == 1300, robust

**************************
*** APPENDIX FIGURE A5 ***
**************************

* Created in the folder "Figure A5"

**************************
*** APPENDIX FIGURE A6 *** 
**************************

* DISTANCE FROM EACH CITY FROM EACH OTHER CITY *

* We estimate the distance
foreach N of numlist 1(1)466 {
foreach X in city`N' {
use finaljjk4, clear
keep if year == 1400
sort city_id
merge city_id using rankall1300
tab _m
drop _m
keep if rank1300 == `N'
tab city_jjk
keep longitude latitude
ren longitude `X'_lon 
ren latitude `X'_lat
save `X'_euclidean, replace
use finaljjk4, clear
keep if year == 1400
keep countryname city_jjk longitude latitude 
ren longitude city_lon
ren latitude city_lat
cross using `X'_euclidean
geodist city_lat city_lon `X'_lat `X'_lon, gen(dist)
collapse (min) dist, by(countryname city_jjk)
ren dist `X'_euclidean
sort countryname city_jjk 
save `X'_euclidean, replace
}
}

use finaljjk4, clear
keep if year == 1300 & mortality != . & pop1300 != .
count
keep countryname city_jjk
foreach N of numlist 1(1)466 {
foreach X in city`N' {
sort countryname city_jjk 
merge countryname city_jjk using `X'_euclidean
tab _m
drop _m
}
}
sort countryname city_jjk 
save euclidean_distance_top, replace

* We obtain the rank of each city. 
use finaljjk4, clear
keep if year == 1300
keep city_jjk city_id pop countryname pop1300
gsort- pop
keep if pop != .
gen rank1300 = _n
keep city_id rank1300 city_jjk countryname pop1300
sort city_id
save rankall1300, replace

* We add to the main data set

use finaljjk4, clear
sort countryname city_jjk
merge countryname city_jjk using euclidean_distance_top
tab _m
drop if _m == 2
drop _m
sort city_id
merge city_id using rankall1300
tab _m
drop _m
sum rank1300, d
keep if year == 1400

* We obtain the coefficients for each regression
* This takes time
quietly {
capture erase table.xls
capture erase table.txt
capture erase table.tex
foreach X of varlist euromena1_wl_euclidean {
local geo "avtemp15001600 elevation cerealclosest potatolowclosest pastoral_weak_closest dist2AMNB_10 rivers_10 longitude latitude"
local ecogeo "lpop1300 DMajorRomRoad_10 DAnyRomRoad_10 DMajRomIntersection_10 DAnyRmRdIntersection_10 dist2landroute_10 dist2landrouteint_10 fair_all HansaFixed aqueduct_10 university"
local pol "monarchy Bcapital representative1300 parliament1300_yn lDParliament dist2bat13001350_100"
local poly3 "longitude2 latitude2 longitude3 latitude3"
foreach N of numlist 1(1)466 {
reg mortality `geo' `ecogeo' `pol' `poly3' city`N'_euclidean `X' [pw = pop1300] if year == 1400 & city_jjk != "MESSINA" & rank1300 != `N', robust cluster(entity1300) 
regsave city`N'_euclidean using coef_city`N', replace pval
}
}
}

use rankall1300, clear
keep if rank1300 <= 466
keep rank1300 city_jjk countryname pop1300
sort rank1300
save rank1300temp, replace

* We combine all coefficients
foreach N of numlist 1(1)466 {
use coef_city`N', clear
gen rank = `N'
save coef_city`N', replace
}
use coef_city1, clear
foreach N of numlist 2(1)466 {
append using coef_city`N'
}
sum coef if rank == 45
ren rank rank1300
sort rank1300
merge rank1300 using rank1300temp
tab _m
drop _m
sum coef stderr pval if rank == 45
* -.0632982 .0138462 .0000232
sum coef, d
* 10th percentile
* We drop Messina 
drop if rank == 45

twoway (kdensity coef if rank1300 <= 50 [w=pop], lpattern(longdash) lcolor(gs8) lwidth(thick))(kdensity coef if rank1300 <= 50, lpattern(solid) lcolor(black) lwidth(thick)), xline(-.0632982) xtitle(Coef of Euclidean distance to the selected city) legend(order(2 "Coefficient of top 50 cities 1300" 1 "City pop 1300 as weights") row(1)) xlabel(-0.05(0.05)0.1) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
* We modify the figure manually
graph use "coef_messina_45.gph"
graph export "FinalFigures\FigureA6.png", replace width(2620) height(1908)

**************************
*** APPENDIX FIGURE A7 ***
**************************

use finaljjk4, clear
keep if samplemort == 1
keep if mortality != .& start_year !=. & start_month !=.
* Graph with mortality and months
gen start_month1 = start_month
gen start_year1 = start_year
foreach X in 1 {
reg mortality start_year`X' if year == 1300
predict mortality`X' if year == 1300, resid
bysort start_month`X': egen start_month`X'_mean = mean(mortality`X') if year == 1300
}

gen start_month1_35 = start_month1+3.5
replace start_month1_35 = start_month1_35 - 12 if start_month1_35 >= 13
sum avtemp15001600 if year == 1400, d
gen warmmean = (avtemp15001600 >= 18.08349)
foreach X in 1 {
bysort start_month`X' warmmean: egen start_month`X'_mean_mean = mean(mortality`X') if year == 1300
}

* based on mean
twoway (scatter start_month1_mean_mean start_month1_35 if warmmean == 1, mcolor(red))(qfit start_month1_mean_mean start_month1_35 if start_month1_35 >= 2.5 & warmmean == 1, lcolor(red) lpattern(solid) lwidth(thick))(scatter start_month1_mean_mean start_month1_35 if warmmean == 0, mcolor(blue) msymbol(diamond) msize(medsmall))(qfit start_month1_mean_mean start_month1_35 if start_month1_35 >= 2.5 & warmmean == 0, lcolor(blue) lpattern(dash) lwidth(thick)), xlabel(1(1)12) ytitle(Mortality (%) Purged from Year of Infection FE) ytitle(, margin(small)) ylabel(-15(5)10) xtitle(Month of Peak Infection (First Infection + 3.5 Months)) xtitle(, margin(medsmall)) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) legend(order(1 "> Median Temp" 2 "Fit > Median" 3 "< Median" 4 " Fit < Median") row(1))
* we modify the figure manually
graph use "tempmean.gph"
graph export "FinalFigures\FigureA7.png", replace width(2620) height(1908)

**************************
*** APPENDIX FIGURE A8 ***
**************************

clear
import excel "coef_panel_figure.xlsx", sheet("Sheet1") firstrow clear
foreach X in coef {
replace `X' = `X'*100 if spec == "log"
}
keep if var == "continuous"
twoway (connected coef year if spec == "level_log_nolag_drop1300", mcolor(black) msize(medsmall) msymbol(circle) mlabel(star) mlabcolor(black))(connected coef year if spec == "level_log_lag_drop1300", mcolor(gs8) msize(medsmall) lpattern(dash) msymbol(circle) mlabel(star) mlabcolor(gs8)), ytitle(Effect of Black Death Mortality (%) in Each Year) xtitle(.) ytitle(, margin(medsmall)) xtitle(, margin(medsmall)) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) xlabel(1200(100)1700) legend(order(2 "Level, log pop, incl. lag of log pop" 1 "Level, log pop, no lag"))
graph use "panel_logpop_fig.gph"
graph export "FinalFigures\FigureA8.png", replace width(2620) height(1908)

**************************
*** APPENDIX FIGURE A9 ***
**************************

use finaljjk4, clear
* We keep some of the variables. 
keep city_jjk year mortality pop1300 anthro_tech_10k_* pop*c pop*
keep if year >= 1200 & year <= 1750
* We generate the land use share variables *
gen landusesh = .
foreach X in 1200 1300 1400 1500 1600 1700 1750 {
replace landusesh = anthro_tech_10k_`X' if year == `X'
}
replace landusesh = landusesh*100

* Country population controls * 
gen popc = .
foreach X in 1200 1300 1400 1500 1600 1700 1750 {
replace popc = pop`X'c if year == `X'
}
gen lpopc = log(popc)
codebook popc lpopc
* City population controls * 
gen citypop = .
foreach X in 1200 1300 1400 1500 1600 1700 1750 {
replace citypop = pop`X'_05 if year == `X'
}
gen lcitypop = log(citypop)
* Mortality * year variables.
foreach X in 1300 1400 1500 1600 1700 1750 {
gen mort_`X' = 0
replace mort_`X' = mortality if year == `X'
}
* We obtain the lag in the land use share.
sort city_jjk year
bysort city_jjk: gen laglandusesh = landusesh[_n-1]
* We run three regressions.
xi: areg landusesh mort_* i.year [w=pop1300], absorb(city_jjk) 
regsave using coef_landuse_noctrls, replace pval
xi: areg landusesh mort_* lpopc lcitypop i.year [w=pop1300], absorb(city_jjk) 
regsave using coef_landuse_ctrls, replace pval
xi: areg landusesh mort_* lpopc lcitypop laglandusesh i.year [w=pop1300], absorb(city_jjk) 
regsave using coef_landuse2_ctrls, replace pval

* We append them.
use coef_landuse_noctrls, clear
ren coef coef_noctrls
ren pval pval_noctrls
keep var coef pval
sort var
save coef_landuse_noctrls2, replace 
use coef_landuse_ctrls, clear
ren coef coef_ctrls
ren pval pval_ctrls
keep var coef pval
sort var
save coef_landuse_ctrls2, replace 
use coef_landuse2_ctrls, clear
ren coef coef_ctrlslag
ren pval pval_ctrlslag
keep var coef pval
sort var
save coef_landuse2_ctrls2, replace 
* We create the figure
use coef_landuse_noctrls2, clear
sort var
merge var using coef_landuse_ctrls2
tab _m
drop _m
sort var
merge var using coef_landuse2_ctrls2
tab _m
drop _m
gen substr= substr(var,1,4)
keep if substr == "mort"
gen year = substr(var,-4,4)
destring year, replace
sort year
* add year 1750
set obs `=_N+1'
replace year = 1200 if year == .
replace coef_ctrls = 0 if year == 1200
replace coef_ctrlslag = 0 if year == 1200
replace coef_noctrls = 0 if year == 1200
sort year
* We use the ones with the controls 
twoway (connected coef_ctrls year, mcolor(black) msize(medsmall) msymbol(circle))(connected coef_ctrlslag year, mcolor(gs8) msize(medsmall) lpattern(dash) msymbol(circle)), ytitle(Effect of Black Death Mortality (%) in Each Year) xtitle(.) ytitle(, margin(medsmall)) xtitle(, margin(medsmall)) graphregion(margin(small) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) xlabel(1200(100)1700) legend(order(2 "Level, log pop, incl. lag of log pop" 1 "Level, log pop, no lag"))
* We modify manually 
graph use "panel_landuse.gph"
graph export "FinalFigures\FigureA9.png", replace width(2620) height(1908)

***************************
*** APPENDIX FIGURE A10 ***
***************************

** Figure created in the folder "Figure A10"

***************************
*** APPENDIX FIGURE A11 ***
***************************

* Land shares over time for each country *
import delimited "anthro_land_use_tech_country_final.csv", clear 
collapse (mean) tech* [iw = landarea1961]
gen count = 1
reshape long tech_country_, i(count) j(year)
drop count
twoway (connected tech_country_ year)
keep if year >= 1100 & year <= 1600
drop if year == 1340 | year == 1350 
replace year = 1353 if year == 1360
ren tech_country_ landsheurope
sort year 
save newlandsh, replace

* Population over time *
clear
import excel "new_country_info_16.xlsx", sheet("Sheet1") firstrow clear
drop if year == .
keep if year >= 1100 & year <= 1600
drop I J
sort year 
merge year using newlandsh
tab _m
tab year if _m == 2
drop _m
drop landsh
ren landsheurope landsh

*** FIGURES ***

* TOTAL POP AND URBANIZATION
twoway (connected pop year, mcolor(black) msize(medlarge) msymbol(circle) lcolor(black) lwidth(medthick) lpattern(solid)) (connected urb_rate year, yaxis(2) mcolor(gs5) msize(medsmall) msymbol(square) lcolor(gs4) lwidth(medthick) lpattern(dash)), ytitle(Total Population (Millions)) ytitle(, margin(medsmall)) xtitle(.) xtitle(, size(zero) color(white)) legend(on order(1 "Total Population" 2 "Urbanization Rate")) graphregion(margin(small) fcolor(none) lcolor(white) ifcolor(white) ilcolor(white))
graph use "graph11A.gph"
graph export "FinalFigures\FigureA11a.png", replace width(2620) height(1908)

* RURAL AND URBAN POP
twoway (connected upop year, mcolor(black) msize(medlarge) msymbol(circle) lcolor(black) lwidth(medthick) lpattern(solid)) (connected rpop year, yaxis(2) mcolor(gs5) msize(medsmall) msymbol(square) lcolor(gs4) lwidth(medthick) lpattern(dash)), ytitle(Urban Population (Millions)) ytitle(, margin(medsmall)) xtitle(.) xtitle(, size(zero) color(white)) legend(on order(1 "Urban Population" 2 "Rural Population")) graphregion(margin(small) fcolor(none) lcolor(white) ifcolor(white) ilcolor(white))
graph use "graph11B.gph"
graph export "FinalFigures\FigureA11b.png", replace width(2620) height(1908)

***************************
*** APPENDIX FIGURE A12 ***
*** APPENDIX FIGURE A13 ***
***************************

* File created above for FIGURE 7

use contrib_ystar_atm, clear
foreach N in 1400 1500 1600 1700 1750 2015 {
gen pchgpop`N'_no`X' = pchgpop`N' - b_m_cer`N'*cer*mortality - b_m_pot`N'*pot*mortality - b_m_pas`N'*pas*mortality+pchgpop`N' - b_m_coa`N'*coa*mortality - b_m_riv`N'*riv*mortality - b_m_rdi`N'*rdi*mortality - b_m_han`N'*han*mortality
* Prediction of population levels. 
gen pop_all`N' = pop1300/100*(100+pchgpop`N')
gen pop_no`N' = pop1300/100*(100+pchgpop`N'_no`X')
gen lpop_all`N' = log(pop_all`N')
gen lpop`N' = log(pop`N')
* We keep one year to have 165 observations. 
keep if year == 1850
* We get the ranks. 
gsort- pop_no`N'
gen rank`N'_no = _n
gen invrank`N'_no = -rank`N'_no
drop rank`N'_no
gsort- pop_all`N'
gen rank`N'_all = _n
gen invrank`N'_all = -rank`N'_all
drop rank`N'_all
gsort- pop`N'
gen rank`N'_true = _n
gen invrank`N'_true = -rank`N'_true
gen diffrank`N' = -invrank`N'_no - (-invrank`N'_all)
}
gsort- pop1300
gen rank1300_true = _n
* Scatterplot with true and predicted w/o fix
foreach N in 1750 {
twoway (scatter invrank`N'_no invrank`N'_all, mlabel(city_jjk) mlabsize(tiny))(lfit invrank`N'_no invrank`N'_all), legend(off) ytitle(Predicted w/o Factor(s)*Mortality Effect(s)) xtitle(Predicted Using All)
}
graph use "collapse1750.gph"
graph export "FinalFigures\FigureA12.png", replace width(2620) height(1908)
* Scatterplot with true and predicted w/o fix
foreach N in 2015 {
twoway (scatter invrank`N'_no invrank`N'_all, mlabel(city_jjk) mlabsize(tiny))(lfit invrank`N'_no invrank`N'_all), legend(off) ytitle(Predicted w/o Factor(s)*Mortality Effect(s)) xtitle(Predicted Using All)
}
graph use "collapse2015.gph"
graph export "FinalFigures\FigureA13.png", replace width(2620) height(1908)

